<template>
    <div class="musicList">
        <!-- 歌单顶部内容 -->
        <div class="musicTop">
            <div class="title">发现好歌单</div>
            <div class="more">查看更多</div>
        </div>
        <!-- 展示得到的接口内容
            1、使用轮播图样式进行展示，loop:自动播放取消
            2、
        -->
        <div class="musicContent">
            <van-swipe :loop="false" :width="150" class="my-swipe" :show-indicators="false">
                <van-swipe-item v-for=" item in musicList" :key="item">
                    <router-link :to = "{path:'/itemMusic',query:{id:item.id}}">
                        <img :src="item.picUrl" alt="" />
                        <span class="playCount">
                            <svg class="icon" aria-hidden="true">
                                <use xlink:href="#icon-24gl-play"></use>
                            </svg>
                            <p>{{ changeCount(item.playCount) }}</p>
                        </span>
                        <span class="name">{{ item.name }}</span>
                    </router-link>
                </van-swipe-item>
            </van-swipe>
        </div>
    </div>
</template>

<script>

import { getMusics } from '@/api/home'

export default {
    data() {
        return {
            musicList: [],
        };
    },
    methods: {
        async getGedan() {
            const res = await getMusics()
            console.log(res)
            this.musicList = res.data.result
        },
        changeCount : function (num) {
            if (num >= 100000000) {
                return (num / 10000000).toFixed(1) + "亿"
            } else if (num >= 10000) {
                return (num / 10000).toFixed(1) + "万"
            }
        }
    },
    mounted() {
        this.getGedan()
    }

}

</script>

<!-- 基于vue3的语法糖实现 -->
<!--  -->


<style lang="less" scoped>
.musicList{
    width: 100%;
    padding: 2vw;
    .musicTop{
        width: 100%;
        display: flex;
        justify-content: space-between;
        margin-bottom: 2vw;
        .title{
            font-size: 6vw;
            font-weight: 800;
        }
        .more{
            margin-top: 0.5vh;
            height: 3vh;
            color:#666;
            border: 1px solid #666;
            border-radius: 4vw;
            padding: 0.2vw 2vw 0.2vw 2vw;
            text-align: center;
            line-height: 3vh;
        }
    }
    .musicContent{
        width: 100%;
        height: 25vh;
        // display: flex;

        .my-swipe{  
            width: 100%;
            
            .van-swipe-item{
                margin: 1vw;
            
                img{
                    width: 100%;
                    height: 100%;
                    border-radius: 2vw; 
                }

                .playCount {
                    position: absolute;
                    top:0.5vh;
                    right: 1vw;
                    display: flex;
                    align-items: center;
                    // background-color: rgba(211,200,1,0.3);
                    // font-size: 4vw;


                    .icon{
                        width: 5vw;
                        height: 5vw;
                    }
                    p{
                        
                        font-size: 3vw;
                    }

                }
            }
        }
    }
}


</style>